using System;

namespace Slaks.Readers
{
	public abstract class BufferReader : Slaks.Readers.AReader
	{
    /// <summary>
    /// buffer source
    /// </summary>
    protected string m_buffer = String.Empty;

    /// <summary>
    /// length of the buffer
    /// </summary>
    protected int m_bufferLength = 0;

    /// <summary>
    /// current index
    /// </summary>
    protected int m_index = 0;

		public BufferReader() {}

		public BufferReader(string buffer)
		{
      m_buffer = buffer;
      m_bufferLength = buffer.Length;
      m_index = 0;
		}

    public BufferReader(Slaks.Filters.AFilter filter) : base(filter)
    {
    }

    public BufferReader(Slaks.Filters.AFilter filter,string buffer) : base(filter)
    {
      m_buffer = buffer;
      m_bufferLength = buffer.Length;
      m_index = 0;
    }

    /// <summary>
    /// Change the source buffer
    /// </summary>
    /// <param name="buffer"></param>
    public void AssingNewBuffer(string buffer)
    {
      m_buffer = buffer;
      m_bufferLength = buffer.Length;
      m_index = 0;
    }

    public override bool Eof()
    {
      return m_index >= m_bufferLength && m_innerBuffer == char.MinValue; 
    }

		/// <summary>
		/// Open stream (BufferReader do not need to open streams)
		/// </summary>
		public override void OpenStream()
		{
			return;
		}


    /// <summary>
    /// Close reader (BufferReader do not need to close streams)
    /// </summary>
    public override void CloseReader()
    {
      return;  
    }
	}
}
